public with sharing class HF_EmailTriggerHandler {
/*
public void OnAccountInsertEmail(List<Account_Email__c> emails){
 if(emails != null && emails.size()>0){ 
    Set<Id> accountId=new Set<Id>();
    Set<Id> accEmailIds = new Set<Id>();
    List<Account_Email__c> accountEmailOldList=new List<Account_Email__c>();
    for(Account_Email__c email:emails){
        accountId.add(email.Account__c);
        accEmailIds.add(email.Id);
    }
    accountEmailOldList=[select Preferred__c,Account__c from Account_Email__c where Preferred__c=true and Account__c IN: accountId AND Id NOT IN: accEmailIds];
    list<Account_Email__c> updateAccEmailList = new list<Account_Email__c>();
    for(Account_Email__c email:emails){
        //String s=email.Email_Type__c;
        if(accountEmailOldList !=null && accountEmailOldList.size()>0){
                if(email.Preferred__c==true){
                    for(Account_Email__c accountEmail:accountEmailOldList)
                          try{
                            if(accountEmail.Account__c == email.Account__c){
                                  accountEmail.Preferred__c=false;
                                  updateAccEmailList.add(accountEmail);
                                  //update accountEmail;
                               }
                            }catch(Exception e){System.debug('# Exception '+e);}
                      }
        }
        else{
            email.Preferred__c=true;
        }        
    }
    
    if(!updateAccEmailList.isEmpty()){
        try{
            system.debug('# updateAccEmailList : '+updateAccEmailList);
            update updateAccEmailList;
        }catch(Exception e1){
            system.debug('# Exception while updating : '+e1);
        }
    }
 }
}
public void OnAccountUpdateEmail(List<Account_Email__c> emails, List<Account_Email__c> oldAccountEmailList){
 if(emails != null && emails.size()>0){ 
    set<Id> accountId = new set<Id>();
    Set<Id> accEmailIds = new Set<Id>();
    List<Account_Email__c> accountEmailOldList = new List<Account_Email__c>();
    List<Account_Email__c> accountEmailOldList1 = new List<Account_Email__c>();
    for(Account_Email__c email : emails){
        if(email.Account__c != null){
            accountId.add(email.Account__c);    
        }
        accEmailIds.add(email.Id);
    }
    //map<Id, list<Account_Email__c>> accEmailMap = new map<Id, list<Account_Email__c>>();
    accountEmailOldList = [select Preferred__c,Account__c from Account_Email__c where Preferred__c=true and Account__c IN: accountId AND ID NOT IN: accEmailIds];
    system.debug('# accountEmailOldList : '+accountEmailOldList);
    
    system.debug('###'+accountEmailOldList);
    //accountEmailOldList1 =[select Id,Preferred__c,Account__c from Account_Email__c where Id IN: id];
    
        
        list<Account_Email__c> updateAccEmailList = new list<Account_Email__c>(); 
        for(Account_Email__c email:emails){
         /*if(oldAccountEmailList !=null && oldAccountEmailList.size()>0){
             for(Account_Email__c e : oldAccountEmailList){
                if(e.Preferred__c && (!email.Preferred__c) && email.Id == e.Id){
                    trigger.new[0].addError('cannot update');  
                }else{
                    if((!e.Preferred__c) && (email.Preferred__c )){*/
                      /*  if(accountEmailOldList !=null && accountEmailOldList.size()>0 ){
                             for(Account_Email__c accountEmail:accountEmailOldList){
                                 system.debug('###'+accountEmail);
                                try{
                                if(accountEmail.Account__c == email.Account__c){
                                      accountEmail.Preferred__c=false;
                                      system.debug('###accountEmail#####'+accountEmail);
                                      updateAccEmailList.add(accountEmail);
                                      //update accountEmail;
                                   }
                             }catch(Exception e1){
                                system.debug('# Exception : '+e1);
                                }
                             }
                        }
                   // }
                    
                // }
                //}
                
                
             //}
             
    }
    
    if(!updateAccEmailList.isEmpty()){
        try{
            system.debug('# updateAccEmailList : '+updateAccEmailList);
            update updateAccEmailList;
        }catch(Exception e){
            system.debug('# Exception while updating : '+e);
        }
    }
 }
}
public void OnContactEmail(List<Contact_Email__c> emails){
if(emails != null && emails.size()>0){  
    List<Id> contactId=new List<Id>();
    List<Contact_Email__c> contactEmailOldList=new List<Contact_Email__c>();
    List<Contact_Email__c> updateContactwebaddList=new List<Contact_Email__c>();
    List<Contact_Email__c> updateContactEmailList=new List<Contact_Email__c>();
    for(Contact_Email__c email:emails){
        contactId.add(email.Contact__c);
    }
    contactEmailOldList=[select Preferred__c,Email_Type__c,Contact__c from Contact_Email__c where Preferred__c=true and Contact__c IN: contactId];
    
    for(Contact_Email__c email:emails){
       
                if(email.Preferred__c==true && contactEmailOldList !=null && contactEmailOldList.size()>0){
                   if(email.Email_Type__c=='Web Address'){
                        for(Contact_Email__c contactEmail:contactEmailOldList){
                            try{
                                if((contactEmail.Contact__c ==email.Contact__c)&& (contactEmail.Email_Type__c=='Web Address')){
                                  contactEmail.Preferred__c=false;
                                  updateContactEmailList.add(contactEmail);
                                 // update contactEmail;
                               }}catch(Exception e){}
                        }
                   }
                       else{
                          for(Contact_Email__c contactEmail:contactEmailOldList){
                            try{
                             if((contactEmail.Contact__c ==email.Contact__c)&& (contactEmail.Email_Type__c!='Web Address')){
                                contactEmail.Preferred__c=false;
                                updateContactwebaddList.add(contactEmail);
                               // update contactEmail;
                               }
                            }catch(Exception e){System.debug('# Exception :'+e);}
                        }
                    }
              
         }
    }
    if(!updateContactEmailList.isEmpty()){
         try{ 
          update updateContactEmailList;
          }catch(Exception e1){system.debug('## Exception while updating : '+e1);}
       }
     if(!updateContactwebaddList.isEmpty()){
         try{ 
          update updateContactwebaddList;
          }catch(Exception e2){system.debug('## Exception while updating : '+e2);}
       }  
    
}
}
*/
}